#ifndef _OPT_H_
#define _OPT_H_
#include <string>
#include <vector>
#include <map>

/*
 * To predeclare this in .h file, use code below
namespace Opt_NS{
    class Opt_C;
}
*/

namespace Opt_NS
{
    namespace Opt
    {
        enum _OptType{text=0, boolean=1};
    }
    typedef Opt::_OptType OptType;

    struct OptOption_S
    {
        std::string sName;
        std::string sInfo;
        std::string sValue;
        std::string sDefault;
        bool bRequire;
        OptType eType;
        OptOption_S():
            sName(""),
            sInfo(""),
            sValue(""),
            sDefault(""),
            bRequire(false),
            eType(Opt::text)
        {}

        std::string toStr()const;
        const char* toCStr()const;
        int toInt()const;
        float toFloat()const;
        double toDouble()const;
        bool toBool()const;
    };
    //
    class Opt_C
    {
        public:
            Opt_C(const std::string& ="-help");
            ~Opt_C();
            void parseOption(int, char**);
            //
            void addOption(const std::string &, const std::string& ="", const std::string& ="", OptType = Opt::text);
            //void addOption(const char* = "", const char* = "", const char* = "", OptType = Opt::text);
            bool setRequireOption(const std::string &, bool=true);
            bool setOptionInfo(std::string, std::string);
            bool setOptionValue(const std::string &, const std::string &);
            //
            OptOption_S getOption(const std::string &)const;
            bool isValidOption(const std::string &)const;
            bool isSet(const std::string &)const;
            bool isParsed()const{return m_bParsed;}
            bool checkValid()const;
            //print
            void printOption()const;
            void printValue()const;
        private:
            std::map<std::string, OptOption_S*> m_mapOptions;
            std::vector<OptOption_S*> m_vOptions;
            std::string m_sExeName;
            std::string m_sHelpOption;
            bool m_bParsed;
    };
}
#endif
